package com.spring.cas.config;

import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;

/**
 * @description:
 * @author: lfc
 * @version: 2020/7/22 14:31
 */
@Configuration
public class PojectBaseConfiguration {

    @Bean
    public HttpMessageConverters fastjsonHttpMessageConverterbak() throws ClassNotFoundException {
        //定义一个转换消息的对象
        FastJsonHttpMessageConverter fastJsonHttpMessageConverterConverter = new FastJsonHttpMessageConverter();
        SerializeConfig fieldFilterConfig = SerializeConfig.getGlobalInstance();

        //添加fastjson的配置信息
        FastJsonConfig fastJsonConfig = new FastJsonConfig();
        fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
        fastJsonConfig.setSerializeConfig(fieldFilterConfig);
        //在转换器中添加配置信息
        fastJsonHttpMessageConverterConverter.setFastJsonConfig(fastJsonConfig);
        HttpMessageConverter<?> converter = fastJsonHttpMessageConverterConverter;
        return new HttpMessageConverters(converter);
    }
}
